import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDStageGlobal {
	/**编号*/
	id,
	/**名称*/
	key,
	/**内容*/
	value,

	/**枚举数量*/
	EnumCount
}



export class CDStageGlobal{
	/**编号*/
	public id: number;
	/**名称*/
	public key: string;
	/**内容*/
	public value: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDStageGlobal.id: return this.id;
			case E_CDStageGlobal.key: return this.key;
			case E_CDStageGlobal.value: return this.value;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDStageGlobal.id: this.id = v; break;
			case E_CDStageGlobal.key: this.key = v; break;
			case E_CDStageGlobal.value: this.value = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDStageGlobal> = new HashMap<number, CDStageGlobal>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDStageGlobal[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDStageGlobal();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].key = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].value = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDStageGlobal{
		return this.datas ? this.datas.get(id) : null;
	}
}
